/**
 * Created by Administrator on 2017/5/19 0019.
 */
onload=function(){
    //轮播图
    var CarouselFigure = document.getElementById("CarouselFigure");//大图
    var radius = document.getElementById("radius"); //圆角
    var rLi = radius.getElementsByTagName("li");
    //console.log(rLi,"rLi")
    var oContent = document.getElementById("content");
    var oNext = document.getElementById("next");
    var oPrev = document.getElementById("prev");

    var timer = null;
    var num = 0;
    //（圆圈）按钮
    oContent.onmouseenter = function(){
        clearInterval(timer);
        oNext.style.display = "block";
        oPrev.style.display = "block";
    }
    oContent.onmouseleave = function(){
        oNext.style.display = "none";
        oPrev.style.display = "none";
        autoplay();

    }
    for(var i = 0; i < rLi.length; i++){
        rLi[i].index = i;
        rLi[i].onclick = function(){
            clearInterval(timer);
            //排他
            for(var j = 0; j < rLi.length; j++){
                rLi[j].style.background = "white";
            }
            rLi[this.index].style.background = "red";
            CarouselFigure.style.left = this.index * -700 + "px";
            autoplay()

        }
    }
    //左右移动
    oNext.onclick = function(){
        clearInterval(timer)
        if(num > rLi.length - 1){
            num = 0;
            CarouselFigure.style.left = 0 + "px";
        }
        CarouselFigure.style.left = num * -700 + "px";
        for(var i = 0; i < rLi.length; i++){
            rLi[i].style.background = "white";
        }
        rLi[num].style.background = "red";

        num++
        console.log(num)
    }
    oPrev.onclick = function(){
        clearInterval(timer)

        CarouselFigure.style.left = CarouselFigure.offsetLeft + 700 + "px";
        for(var i = 0; i < rLi.length; i++){
            rLi[i].style.background = "white";
        }
        rLi[num].style.background = "red";
        if(num <= 0){
            num = 3;
            CarouselFigure.style.left = (num - 1) * -700 + "px";
        }
        num--;
        console.log(num, "num")
    }
    function autoplay(){
        timer = setInterval(function(){
            if(num >= rLi.length){
                num = 0;
            }
            for(var i = 0; i < rLi.length; i++){
                rLi[i].style.background = "white";
            }
            rLi[num].style.background = "red";
            CarouselFigure.style.left = num * -700 + "px";
            num++
        }, 2000)
    }

    autoplay()


    //商品剩余时间

    //这个函数是为了适应格式 比如：01分01秒;
    function p(n){
        return n < 10 ? '0' + n : n;
    }

    function newDate(){

        var oCountdown = document.getElementById("cover");
        var oSpan = oCountdown.getElementsByTagName("span");
        console.log(oSpan)
        //当前时间
        var startTime = new Date();
        //结束时间
        var endTime = new Date("2017-6-01 12:00:00");
        //获取转化后返回的时间差
        var Countdown = parseInt((endTime.getTime() - startTime.getTime()) / 1000)

        //获取天数
        var d = parseInt(Countdown / (24 * 60 * 60));

        //获取小时数
        var h = parseInt(Countdown / (60 * 60) % 24);
        console.log(h, "h")
        //获取分钟
        var m = parseInt(Countdown / (60) % 60);
        console.log(m, "m")
        //获取秒
        var s = parseInt(Countdown % 60);
        console.log(s, "s")
        var txt = p(d) + "天" + p(h) + "时" + p(m) + "分" + p(s) + "秒";

        oSpan[3].innerHTML = txt;

    }

    newDate()
    //返回顶部
    var oBack=document.getElementById("oBack");
    var hidApp=document.getElementById("hidApp");

    for(var i=0;i<oBack.children.length;i++){

        oBack.children[i].index=i;
        oBack.children[i].onmouseenter=function(){
            console.log('enter----this.index', this.index)
            for(var j=0;j<oBack.children.length;j++){
                console.log('enter----111', j)
                oBack.children[j].style.background="gray"
                oBack.children[j].style.textDecoration="none"
            }
            oBack.children[this.index].style.background="red"
            oBack.children[this.index].style.textDecoration="underline"

        };

        oBack.onmouseleave=function(){
            for(var j=0;j<oBack.children.length;j++){
                oBack.children[j].style.background="gray"
            }
            hidApp.style.display="none"
        }
        
    }
    oBack.children[0].onmouseenter=function(){
        console.log('enter----13333')
        hidApp.style.display="block";
        
        for(var j=0;j<oBack.children.length;j++){
            oBack.children[j].style.background="gray"
            oBack.children[j].style.textDecoration="none"
        }
        oBack.children[0].style.background="red"
        oBack.children[0].style.textDecoration="underline"
    }
    oBack.children[0].onmouseleave=function(){
        hidApp.style.display="none";
        oBack.children[0].style.background="gray";
        oBack.children[0].style.textDecoration="none"
    }
    //标题栏固定
    $(function(){

        var headlineH=$("#fixHeadline").offset().top;
        //console.log(headlineH,"headlineH")
        $(window).scroll(function(){
            var scroH = $(this).scrollTop();
            if(scroH>=headlineH){
                $("#fixHeadline").css({"position":"fixed","zIndex":"1000","background":"white","top":0,"margin-top":$("#headlineH").offsetTop});
            }else if(scroH<headlineH){
                $("#fixHeadline").css({"position":"static","margin":"0 auto"});
            }
        })
    })

    $(function(){
        $(window).scroll(function(){
            var scroH = $(document).scrollTop();
            var oBack=$("#oBack");
            console.log(scroH);
            if(scroH>1000){

                console.log(oBack);
                // oBack.css({"display":"none"})

                oBack.animate({"opacity":1},100);

            }else{
                oBack.animate({"opacity":0},100)

            }
        })
    })

}